<template>
    <MyHead title="修改地址" @click="goback"></MyHead>

    <van-address-edit :save-button-text="text" :address-info="ressobj" :area-list="areaList" show-delete show-set-default
        show-search-result :search-result="searchResult" :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave"
        @delete="onDelete" @change-detail="onChangeDetail" />
</template>

<script setup lang="ts">
import { ref } from 'vue'
import { useRoute } from 'vue-router'
import { areaList } from '@vant/area-data'
import { useCommon } from '@/hooks/useCommon';
import { ress, update, ressdelete } from '../api/map'
import { onMounted } from 'vue';

const { goback } = useCommon()
const route = useRoute()
const ressobj = ref()
const text = '修改'
const userid: any = localStorage.getItem('id')




onMounted(() => {
    ress(userid).then(res => {
        const item = route.params.index
        ressobj.value = res.data[item]
    })
})


//  修改
const onSave = (value: any) => {
    console.log(value)
    update(value).then(res => {
        console.log(res)
        goback()
    })
}




//  删除
const onDelete = () => {
    ressdelete(ressobj.value.addressid).then(res => {
        goback()
    })
}


</script>